"use client";

import { useState } from "react";
import { useRouter } from "next/navigation";
import { signIn } from "@/lib/auth-client";

export default function SignInPage() {
    const router = useRouter();
    const [error, setError] = useState<string | null>(null);

    async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
        e.preventDefault();
        const data = await signIn.social({
            /**
             * The social provider ID
             * @example "github", "google", "apple"
             */
            provider: "github",
            /**
             * A URL to redirect after the user authenticates with the provider
             * @default "/"
             */
            callbackURL: "/dashboard",
            /**
             * A URL to redirect if an error occurs during the sign in process
             */
            errorCallbackURL: "/error",
            /**
             * A URL to redirect if the user is newly registered
             */
            newUserCallbackURL: "/welcome",
            /**
             * disable the automatic redirect to the provider. 
             * @default false
             */
            disableRedirect: false,
        });
        console.log(data)
    }

    return (
        <main className="max-w-md h-screen flex items-center justify-center flex-col mx-auto p-6 space-y-4 text-white">
            <h1 className="text-2xl font-bold">github</h1>

            {error && <p className="text-red-500">{error}</p>}

            <form onSubmit={handleSubmit} className="space-y-4">

                <button
                    type="submit"
                    className="w-full bg-white text-black font-medium rounded-md px-4 py-2 hover:bg-gray-200"
                >
                    github登录
                </button>
            </form>
        </main>
    );
}